﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using StackExchange.Redis;
using WebApi.Models;

namespace WebApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class HomeController : ControllerBase
    {
        private readonly IOptionsSnapshot<SmtpOptions> _options;
        private readonly IConnectionMultiplexer _connectionMultiplexer;

        public HomeController(IOptionsSnapshot<SmtpOptions> options,IConnectionMultiplexer connectionMultiplexer)
        {
            _options = options;
            _connectionMultiplexer = connectionMultiplexer;
        }


        [HttpGet]
        public string Index()
        {
            var opt = _options.Value;
            var timeSpan = _connectionMultiplexer.GetDatabase().Ping();
            return $"smtp:{opt} timeSpan:{timeSpan}";
        }
    }
}
